/* eslint-disable no-unused-vars */
/*
 * @Author: AHANG
 * @Date: 2022-04-12 14:33:41
 * @LastEditors: AHANG
 * @LastEditTime: 2022-07-19 15:21:05
 * @Description:
 */
// node 后端服务器
const userApi = require("./api/userApi");
const bodyParser = require("body-parser");
const express = require("express");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
//导入上传文件中间件，能帮助我们实现接收文件的接口
const multer = require("multer");
//接收到的文件放uploads文件夹
const upload = multer({ dest: "uploads/" });
//使得让外部通过链接可以访问这个文件夹里文件（ 地址 + 端口 / 文件名 ）便可访问
app.use(express.static("uploads"));
app.use(express.json());
// app.all("*", function (req, res, next) {
//   console.log(req.method);
//   res.header("Access-Control-Allow-Origin", "*");
//   res.header("Access-Control-Allow-Headers", "Content-type");
//   res.header(
//     "Access-Control-Allow-Methods",
//     "PUT,POST,GET,DELETE,OPTIONS,PATCH"
//   );
//   res.header("Access-Control-Max-Age", 1728000); //预请求缓存20天
//   next();
// });
// 后端api路由
// app.use("/api/user", userApi);
app.use("/user", userApi);
// 监听端口
app.listen(5000, () => console.log(`Example app listening on port 5000!`));
